package com.prd.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.prd.config.LoginInterceptor;
import com.prd.mapper.EntBudgetNapeMapper;
import com.prd.model.EntBudgetNape;
import com.prd.model.LoginUser;
import com.prd.service.EntBudgetNapeService;
import com.prd.util.UserInfoUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class EntBudgetNapeServiceImpl extends ServiceImpl<EntBudgetNapeMapper, EntBudgetNape> implements EntBudgetNapeService {

    @Autowired
    private EntBudgetNapeMapper entBudgetNapeMapper;

    @Override
    public int insertInfo(EntBudgetNape entBudgetNape) {
        LoginUser loginUser = LoginInterceptor.threadLocal.get();
        BeanUtils.copyProperties(UserInfoUtil.recordInfo(loginUser.getId(), loginUser.getName(), true), entBudgetNape);
        return entBudgetNapeMapper.insert(entBudgetNape);
    }

    @Override
    public int updateInfo(EntBudgetNape entBudgetNape) {
        LoginUser loginUser = LoginInterceptor.threadLocal.get();
        BeanUtils.copyProperties(UserInfoUtil.recordInfo(loginUser.getId(), loginUser.getName(), false), entBudgetNape);
        return entBudgetNapeMapper.updateById(entBudgetNape);
    }
}
